package com.lic.system.service.Impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lic.system.mapper.UserMapper;
import com.lic.system.pojo.SysLogin;
import com.lic.system.pojo.User;
import com.lic.system.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * @author Hewb
 * @ClassName: userServiceImpl
 * @Description: TODO
 * @date: 2020/7/11 9:25
 * @since JDK 1.8
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {


    @Resource
    UserMapper userMapper;

    @Override
    public SysLogin queryByUserName(String userName) {
        SysLogin sysLogin = userMapper.queryByUserName(userName);
        return sysLogin;
    }

    @Override
    public User queryUser(Integer userId) {
        User user = userMapper.selectById(userId);
        return user;
    }

    @Override
    public int insertUser(User user) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.like("user_name", user.getUserName());
        Integer integer = userMapper.selectCount(queryWrapper);
        if(integer>1){
           throw new RuntimeException("用户名已存在");
        }
        int insert = userMapper.insert(user);

        return insert;
    }


}
